namespace SimpleWebServices.Web.Mvc
{
    using System;
    using System.Web;
    using System.Web.Mvc;
    using Moq;
    using SimpleWebServices.Web;
    using Xunit;

    public sealed class ContentLocationAttributeFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<ContentLocationAttribute>()
                .DerivesFrom<ActionFilterAttribute>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .IsDecoratedWith<AttributeUsageAttribute>()
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new ContentLocationAttribute());
        }

        [Fact]
        public void op_OnActionExecuted_ActionExecutedContextNull()
        {
            Assert.Throws<ArgumentNullException>(() => new ContentLocationAttribute().OnActionExecuted(null));
        }

        [Fact]
        public void op_OnActionExecuted_ActionExecutedContextWithModel()
        {
            string location = "http://example.com/path?name=value";

            var mock = new Mock<HttpContextBase>();
            mock.SetupGet<Uri>(x => x.Request.Url).Returns(new Uri(location)).Verifiable();
            mock.Setup(x => x.Response.AppendHeader("Content-Location", location)).Verifiable();

            new ContentLocationAttribute().OnActionExecuted(new ActionExecutedContext()
            {
                HttpContext = mock.Object,
                Controller = new TestController<Resource>(new TestResource())
            });

            mock.VerifyAll();
        }
    }
}